<?php
/**
 * 简单风格的JS分页类
 *
 * @since 0.1.1
 * @package net.4kiki.pager.js
 */
class ISimpleJsPager extends IAbstractPager implements IJsPager {
	private $jsFunc;
	
	/**
	 * 设置JS回调函数
	 *
	 * @param string $func 用户传回当前页数的JS函数
	 * @since 0.1.1
	 */
	public function setJsFunc($func) {
		$this->jsFunc = $func;
	}
	
	public function __toString() {
    	$page = array();
        $page["input"] = $this->message("pager_input_pageno") . " <input type=\"text\" name=\"pageno\" onblur=\"{$this->jsFunc}(this.value,this)\" size=\"3\" maxlength=\"10\" />  ";
        $page["no"] = sprintf($this->message("pager_current_pageno"), $this->current()) . ", " . sprintf($this->message("pager_total_page"), $this->length()) . " |  ";
        $page["first"] = ($this->length() > 0) ? "<a href=\"\" onclick=\"{$this->jsFunc}(1,this);return false;\" target=\"_self\">" . $this->message("pager_first") . "</a>  ":$this->message("pager_first") . "  ";
        $page["pre"] = ($this->current() > 1)? "| <a href=\"\" onclick=\"{$this->jsFunc}(" . ($this->current() - 1) . ",this);return false;\" target=\"_self\">" . $this->message("pager_prev") . "</a> ":"| " . $this->message("pager_prev") . " ";
        $page["next"] = ($this->current() <= $this->length() - 1)?"| <a href=\"\" onclick=\"{$this->jsFunc}(" . ($this->current() + 1) . ",this);return false;\" target=\"_self\">" . $this->message("pager_next") . "</a> ":"| " . $this->message("pager_next") . " ";
        $page["last"] = ($this->length() > 0)?"| <a href=\"\" onclick=\"{$this->jsFunc}(" . $this->length() . ",this);return false;\" target=\"_self\">" . $this->message("pager_last") . "</a>":"| " . $this->message("pager_last");

        //构造页码显示
        $string = implode("", $page);
        
        return $string;
	}
}

?>